package com.eva.news.cms.databuilder.builders.cms;

import com.eva.news.cms.biz.article.CmsArticleBiz;
import com.eva.news.cms.biz.article.dto.QueryLatestCmsArticleDTO;
import com.eva.news.cms.biz.article.vo.CmsArticleProfileVO;
import com.eva.news.cms.databuilder.AbstractTemplateDataBuilder;
import com.eva.news.cms.databuilder.bo.TemplateDataParameters;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class LatestArticleListBuilder extends AbstractTemplateDataBuilder<List<CmsArticleProfileVO>> {

    @Resource
    private CmsArticleBiz cmsArticleBiz;

    @Override
    public List<CmsArticleProfileVO> build(TemplateDataParameters parameters) {
        // 获取参数
        Integer capacity = parameters.getInteger("latestCapacity", 10);
        String categoryUid = parameters.getString("latestCategoryUid", null);
        return cmsArticleBiz.findLatestProfileList(QueryLatestCmsArticleDTO.builder()
                .capacity(capacity)
                .categoryUid(categoryUid)
                .build());
    }
}
